class Solution
{
public:
    int maximalNetworkRank(int n, vector<vector<int>> &roads)
    {
        vector<unordered_set<int>> adjTable(n);
        for (auto &road : roads)
        {
            adjTable[road[0]].insert(road[1]);
            adjTable[road[1]].insert(road[0]);
        }
        int maxRank = 0;
        for (int i = 0; i < n; ++i)
        {
            for (int j = i + 1; j < n; ++j)
            {
                int rank = adjTable[i].size() + adjTable[j].size();
                if (adjTable[i].count(j))
                {
                    --rank;
                }
                maxRank = max(maxRank, rank);
            }
        }
        return maxRank;
    }
};